<?php
/**
 * Created by PhpStorm.
 * User: xeng
 * Date: 2017/12/28
 * Time: 15:49
 * 会员管理类
 */
/*
 * 会员管理类
 */
namespace Home\Controller;
use Think\Controller;
use Think\Model;


class MemberController extends AuthController
{
    //private  $page_count=20;
    protected $con ='DB_CONFIG1';

     /* 会员查询 方法
     * search
     *
     * 多表查询
     * select a.*,b.* from user as a left join userinfo as b on a.id=b.uid
     * $lists = M("user")->table("user as a")->join("userinfo as b")->field("a.*,b.*")->select();
     *
     */
    public function index()
    {
       // echo $successRate = floor((14/17)*10000)/10000*100;
        $this->CheckPower('3');
        $this->CheckPower('3001');
        $canshu = 0;
        if(strpos(",".$_SESSION["ltq_game_admin_user"]['power'], "3013")){
            $canshu = 1;
        }
        if($_SESSION['ltq_game_admin_user']['power'] == 'all'){
            $canshu = 1;
        }
        $this->assign('canshu', $canshu);
        $this->assign('selects', $this->selects());
        $this->display('search');
    }


    public function test(){
        $this->CheckPower('3');
        $this->CheckPower('3001');
        $this->display('search2');
    }


    public function gettest(){
        $useraccount = M('','',$this->con);
            $url = pageurl(__SELF__);
            $pagesize = empty($url['limit'])?90:$url['limit'];
            $page = empty($url['page'])?1:$url['page'];
            $state = ($page-1)*$pagesize;

            $where['usertype'] = array('eq','4');//代理

            if($url['gameid'] > 0 && !empty($url['gameid'])){
                $where['gameid'] = array('eq',$url['gameid']);
            }

            if(!empty($url['nikename'])){

                $r=$this-> actionLog($url['nikename'],'模糊查询了','用户');
                $where['nickname'] = array('like','%'.$_GET['nikename'].'%');
            }
            if(!empty($url['rechargest']) && !empty($url['rechargend'])){
                $where['recharge'] = array('between',($url['rechargest']*1000).','.($url['rechargend']*1000));
            }
        $list = $useraccount->table('view_game')->where($where)->limit($state,$pagesize)->select();
        foreach ($list as $key => $value) {
            $list[$key]["goldnum"] =0;
            $g=$useraccount->table('data_excharge')->field('SUM(price) as price')->where("`status`='1' and gameid=".$value['gameid'])->select();   //提现数量
            if(isset($g[0]['price'])){
                $list[$key]["goldnum"] =$g[0]['price'];
            }

            $list[$key]["score"] =round($value['score']/1000,2);  //现金数量
            $list[$key]["recharge"] =round($value['recharge']/1000,2);  //充值金额
        }

            $data['code'] = 0;
            $data['message'] = '';
            $data['count'] = count($list);
            $data['data'] = $list;
            $this->ajaxReturn($data,'json');

    }


    ///随机取
    function GetRandStr($len) {
        $chars = array(
            'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');
        $charsLen = count($chars) - 1;
        shuffle($chars);
        $output = '';
        for ($i = 0; $i < $len; $i++) {
            $output .= $chars[mt_rand(0, $charsLen)];
        }
        return $output;
    }

    /*
     * 用户充值信息
     *
     */
    public function getsearch(){
        $useraccount = M('','',$this->con);
        //2019-1-10 增加查询单个普通玩家
        if(strpos(",".$_SESSION["ltq_game_admin_user"]['power'], "3012")){
            $arr=array_merge($_POST,$_GET);
            $where =" usertype = 2 ";
            $nikename="";
            if ($arr['nikename'] || $arr['nikename']) {
                $nikename = $arr['nikename'];
                // $nikename = "'" . trim($nikename) . "'";
                $where .= " AND nickname = '" .$nikename."'";
                $f = " gameid  = ";
                $where = intval($arr['gameid']) ? $where.' and ' .$f. intval($arr['gameid']) : $where;
            }
            $lists=[];
            if($nikename != "" || !empty($arr['gameid'])){
                // $nikename=1;
                $DD = " AND gameid  = ";
                $where = intval($arr['gameid']) ? $where.$DD.intval($arr['gameid']) : $where;
                $list = $useraccount->table('view_game')->where($where)->select();

                foreach ($lists as $key => $value) {
                    $list[$key]["goldnum"] = $useraccount->table('data_excharge')->where('status=1 and gameid='.$value['gameid'])->count();   //提现数量
                }
            }

            $data['code'] = 0;
            $data['message'] = $where;
            $data['count'] = 1;
            $data['data'] = $list;
            $this->ajaxReturn($data,'json');
            exit();
        }

        S(array('type'=>'file','prefix'=>'usergmae','expire'=>60*60*24));

        $url = pageurl(__SELF__);
        $pagesize = empty($url['limit'])?90:$url['limit'];
        $page = empty($url['page'])?1:$url['page'];
        $state = ($page-1)*$pagesize;
        $where['_string'] = 'ongameid IS null'; //默认查询离线

        if(!empty($_SESSION["ltq_game_admin_user"]['blacklist'])){
            $where['gameid'] = array('not in',$_SESSION["ltq_game_admin_user"]['blacklist']);
        }

        if($url['gameid'] > 0 && !empty($url['gameid'])){
            unset($where['_string']);
            $where['gameid'] = array('eq',$url['gameid']);
            $id = $url['gameid'];

            if(strpos(",".$_SESSION["ltq_game_admin_user"]['blacklist'], "$id")!=false) {
                $data['code'] = 1;
                $data['msg'] = '你没有权限查询该用户,请联系管理员';
                $this->ajaxReturn($data,'json');
            }
            $this-> actionLog($id,'查询了accountid为','用户');
        }

        if(!empty($url['nikename'])){
            unset($where['_string']);
            $r=$this-> actionLog($url['nikename'],'模糊查询了','用户');
            $where['nickname'] = array('like','%'.$_GET['nikename'].'%');
        }
        if(!empty($url['rechargest']) && !empty($url['rechargend'])){
            unset($where['_string']);
            $where['recharge'] = array('between',($url['rechargest']*1000).','.($url['rechargend']*1000));
        }
        if(!empty($url['phonenum'])){
            unset($where['_string']);
            $where['phonenum'] = array('eq',$url['phonenum']);
        }
        if(!empty($url['status'])){

            switch ($url['status']){
                case '0':
                    unset($where['_string']);
                    $this-> actionLog('离线玩家','查询了所有','信息');
                    $where['_string'] = 'ongameid IS null'; //离线
                    break;
                case '1':
                    unset($where['_string']);
                     $where['usertype'] = array('eq','3');//代理
                    break;
                case '2':
                    //$where['usertype'] = array('like','%'.$url['status'].'%');
                    unset($where['_string']);
                    $this-> actionLog('在线玩家','查询了所有','信息');

                    $redis = new \Redis();
                    $redis->connect(C('DB_REDIS'),C('REDIS_PORT'));
                    $redis->auth(C('REDIS_PWD'));
                    $game = $redis->hKeys('game_online');
                    $a="";
                    foreach ($game as  $g){
                        $a.=$g.',';
                    }
                    $where['accountid'] = array('in',substr($a,0,-1));//在线
                    break;
                case '3':
                    unset($where['_string']);  //删除默认值离线查询全部
                    $this-> actionLog('玩家','查询了所有','信息');
                    break;
                case '4':
                    // $where['usertype'] = array('like','%'.$url['status'].'%');
                    unset($where['_string']);
                    $where['disablelogin'] = array('eq',1);//冻结玩家
                    break;
                case '5':
                    unset($where['_string']);
                    $where['usertype'] = array('eq',4);//测试账号
                    break;
                default:
                    break;
            }
        }

        if(strpos(",".$_SESSION["ltq_game_admin_user"]['power'], "3012")){
            $count=empty($where)?0:1;
            $list = $useraccount->table('view_game')->where($where)->select();
        }else{
            $list = S('member_list_'.$page.$pagesize);
            $count = S('member_count');
            $count2 =$useraccount->table('view_game')->where($where)->count();
            if($count < 0 || $count !=$count2 || empty($list) || !empty($url['gameid']) || !empty($url['nikename']) || !empty($url['rechargest'])){
                $s = $useraccount->table('view_game')->fetchSql(true)->where($where)->limit($state,$pagesize)->select();
                $list = $useraccount->table('view_game')->where($where)->limit($state,$pagesize)->select();
                foreach ($list as $key => $value) {
                    $list[$key]["goldnum"] =0;
                    $g=$useraccount->table('data_excharge')->field('SUM(price) as price')->where("`status`='1' and gameid=".$value['gameid'])->select();   //提现数量
                    if(isset($g[0]['price'])){
                        $list[$key]["goldnum"] =$g[0]['price'];
                    }

                    $list[$key]["score"] =round($value['score']/1000,2);  //现金数量
                    $list[$key]["recharge"] =round($value['recharge']/1000,2);  //充值金额
                }
                S('member_list_'.$page.$pagesize,$list);
                $count = $count2;
                S('member_count',$count2) ;
            }
        }

        $data['code'] = 0;
        $data['message'] = $s;
        $data['count'] = $count;
        $data['data'] = $list;
        $this->ajaxReturn($data,'json');
    }


    public function gametest(){
        if(!strpos(",".$_SESSION["ltq_game_admin_user"]['power'], "3013")){
            if($_SESSION["ltq_game_admin_user"]['power'] != "all"){
                $data['code'] = 0;
                $data['msg'] = "操作失败，你没有相关权限。。";
                $this->ajaxReturn($data);
            }
        }
        $gameid = $_GET['gameid'];
        $serverID = C('DATA_HOST');
        $id_int = intval($gameid);
        //准备数组
        $command=array(
            'gameid'=>$id_int
        );
        $command = json_encode($command);
        $rpcname="testuser";
        $time=date("Y-m-d H:i:s",time());
        $add['ServerIPAddr'] =$serverID;
        $add['Command'] =$command;
        $add['RpcName'] =$rpcname;
        $add['Time'] =$time;
        $commands = M('','','DB_CONFIG1');
        $save['usertype']=4;
        $s = $commands->table('data_useraccount')->where("gameid=$gameid")->save($save);
        $re = $commands->table('data_command')->add($add);
        $data['code'] = 0;
        $data['msg'] = "操作失败";
        if($re && $s){
            $data['code'] = 1;
            $data['msg'] = "操作成功";
        }
        $this->ajaxReturn($data);
    }

    /*
     * 修改 登陆密码 / 银行卡密码 / 修改金币
     * $id  ,$amendField  需要修改的字段
     *
     */
    public function amend()
    {
        if (IS_POST) { //修改
            //登陆密码 分支
            if ($_POST['pwd']) {
                //验证权限
                $this->CheckPower('3006');
                //修改 登陆密码
                if ($_POST['gameid']) {
                    if($_POST['pwd']!=$_POST['respwd']){
                        $this->error("输入的密码不一致");
                    }
                    $data['pwd'] = $_POST['pwd'];
                    $id_int = intval($_POST['gameid']);
                    $serverID = C('DATA_HOST');
                    //准备数组
                    $command=array(
                        'pwd'=>$_POST['pwd'],
                        'gameid'=>$id_int
                    );
                    $command = json_encode($command);
                    $rpcname="resetpwd";
                    $time=date("Y-m-d H:i:s",time());
                    $add['ServerIPAddr'] =$serverID;
                    $add['Command'] =$command;
                    $add['RpcName'] =$rpcname;
                    $add['Time'] =$time;
                    $commands = M('','','DB_CONFIG1');
                    $re = $commands->table('data_command')->add($add);
                    $r=$this->actionLog((int)($id_int),'修改了gameid为','用户的登录密码');
                    if ($re !==false) {
                        $this->success("修改成功");
                    } else {
                        $this->error("修改失败");
                    }
                }
            }
            // $this->display();
            die;

        }
        if (IS_GET) { //展示
            $id = $_GET['id'];
            $amendField = $_GET['f'];

            $useraccount = M('','','DB_CONFIG1');
            $count2 =$useraccount->table('data_useraccount')->field('accountid,gameid,nickname,disablelogin,account')->where('accountid='.$id)->find();
            if (empty($count2)) {
                $this->err404();
            }
        }

        //dump($data);
        $this->assign('data', $count2);
        $this->display('amend');
    }

    /*
     * 封号
     * 传json 给游戏服务器
     * 修改dis
     *｛"user_id":1｝踢人kick_user
     * ｛"userid":1｝封号forbid_user
     *
     */
    public function disablelogin()
    {
        $commands = M('','','DB_CONFIG1');
        $weblog = M();
       // $this->CheckPower('3008');
        if($_SESSION["ltq_game_admin_user"]['power']!='all'){
            $power='3008,';
            if (strpos($_SESSION["ltq_game_admin_user"]['power'], $power)===false) {
                $data['code'] = 0;
                $data['msg'] = '你没有相关权限，请联系管理员。。。';
                $this->ajaxReturn($data);
            }
        }
        $serverID = C('DATA_HOST');
        $id_int = intval($_GET['id']);
        $id_str = $_GET['id'];
        $content=$_GET['content'];
        //准备数组
        $command=array(
            'forbid'=>0,
            'forbidtype'=>8,
            'data'=>$id_int
        );
        $command = json_encode($command);
        $rpcname="forbid_user";
        $time=date("Y-m-d H:i:s",time());
        $add['ServerIPAddr'] =$serverID;
        $add['Command'] =$command;
        $add['RpcName'] =$rpcname;
        $add['Time'] =$time;
        $lists=  $commands->table('data_useraccount')->field('accountid,account,gameid,nickname,disablelogin,phonenum')->where("gameid=$id_int")->select();
        $game = reset($lists);
        $web['accountid'] = $game['accountid'];
        $web['datetime']  =date('Y-m-d H:i:s',time());
       // $web['account'] = $account = $game['account'];
        $web['gameid']  =$game['gameid'];
        $web['nikename'] = $game['nickname'];
        $web['phonenum']  = $game['phonenum']?$game['phonenum']:0;
        $web['operatorid']  = $_SESSION['ltq_game_admin_user']['id'];
        $web['operator']  = $_SESSION['ltq_game_admin_user']['name'];
        $web['content'] =  $content;

        $weblog->startTrans();  //开启事物
        $result=  $commands->table('data_command')->add($add);
        if(is_array($lists)){
            $results = $weblog->table('ltq_disablelogin')->add($web);
        }
        if($result && $results){
            $weblog->commit();
            $r=$this->actionLog((int)($id_int),'封了accountid为','用户');
            $data['code'] = 1;
            $data['msg'] = "封号请求已发出，gameid为:$id_str";
        }else{
            $data['code'] = 0;
            $data['msg'] = '操作失误，事物提交失败';
            $weblog->rollback();
        }
        $this->ajaxReturn($data);
    }

    /*
     * 踢人
     * 传json 给游戏服务器
     *
     * ｛"user_id":1｝踢人kick_user
     * ｛"userid":1｝封号forbid_user
     */
    public function kickOut()
    {
        if($_SESSION["ltq_game_admin_user"]['power']!='all'){
            $power='3008,';
            if (strpos($_SESSION["ltq_game_admin_user"]['power'], $power)===false) {
                $data['code'] = 0;
                $data['msg'] = '你没有相关权限，请联系管理员。。。';
                $this->ajaxReturn($data);
            }
        }
        $commands = M('','','DB_CONFIG1');
        $serverID = C('DATA_HOST');
        $id_int = intval($_GET['id']);
        $id_str = $_GET['id'];
        //准备数组
        $command=array(
            'gameid'=>$id_int
        );
        $command = json_encode($command);
        $rpcname="kick_user";
        $time=date("Y-m-d H:i:s",time());
        $add['ServerIPAddr'] =$serverID;
        $add['Command'] =$command;
        $add['RpcName'] =$rpcname;
        $add['Time'] =$time;
        $result=  $commands->table('data_command')->add($add);
        $r=$this->actionLog((int)($id_int),'踢了accountid为','用户');
        if($result===null){
            $data['code'] = 0;
            $data['msg'] = "踢人请求失败，gameid为:$id_str";
        }else{
            $data['code'] = 1;
            $data['msg'] = "踢人封号请求已发出，gameid为:$id_str";
        }

        $this->ajaxReturn($data);
    }

    
    /*
     * 用户充值信息
     *
     */
    public function messagebuy()
    {
        $this->CheckPower('3003');
        $url = pageurl(__SELF__);
      //  header("Location: /bankrecored/search.html?user=".$url['gameid']);

        $this->assign("gameid",$url['gameid']);
        $this->assign("tradetype",6);
        $this->display('Bankrecored/search');
    }
    //游戏详情
    public function showmessagebunkoall(){
        $this->CheckPower('3005');
        $url = pageurl(__SELF__);

        $this->assign("gameid",$url['gameid']);
        $this->assign("time",date('Y-m-d'));
        $this->assign("selects",$this->getGameGerverId());
       $this->display('messagebunko_all');
    }



    //游戏详情
    public function getgame_player(){
        S(array('type'=>'file','prefix'=>'game_player','expire'=>60*60*24));
        $useraccount = M('','','DB_CONFIG2');
        $url = pageurl(__SELF__);
        $pagesize = empty($url['limit'])?10:$url['limit'];
        $page = empty($url['page'])?1:$url['page'];
        $state = ($page-1)*$pagesize;

        if($url['gameid'] > 0 && !empty($url['gameid'])){
            $where['gameid'] = array('eq',$url['gameid']);
        }

        if(!empty($url['time']) && !empty($url['end'])){
            $where['time'] = array('between',array($url['time'],$url['end']));
        }
        if(!empty($url['serverid'])){
            $where['serverid'] = array('eq',$url['serverid']);
        }

        if($url['time'] != date('Y-m-d')){
            $list = S('game_player'.$page.$pagesize.$url['gameid']);
            $count = S('game_player_count'.$url['gameid']);
            $count2 =$useraccount->table('game_player')->where($where)->count();
            if($count < 1 || $count !=$count2 || empty($list) || !empty($url['gameid']) || !empty($url['time']) || !empty($url['serverid'])){
                $list = $useraccount->table('game_player')->where($where)->limit($state,$pagesize)->order('time desc')->select();
                S('game_player'.$page.$pagesize.$url['gameid'],$list);
                $count = $count2;
                S('game_player_count'.$url['gameid'],$count2);
            }
        }else{
            $count =$useraccount->table('game_player')->where($where)->count();
            $list = $useraccount->table('game_player')->where($where)->limit($state,$pagesize)->order('time desc')->select();
           // $s = $useraccount->table('game_player')->where($where)->fetchSql(true)->limit($state,$pagesize)->select();
        }

        foreach ($list as $key => $value) {
            $list[$key]["tax"] =round($value['tax']/1000,2);  //税收
            $list[$key]["rewardscore"] =round($value['rewardscore']/1000,2);  //现金数量
            $list[$key]["betscore"] =round($value['betscore']/1000,2);  //现金数量
            $list[$key]["caculscore"] =round($value['caculscore']/1000,2);  //现金数量
            $list[$key]["currentscore"] =round($value['currentscore']/1000,2);  //充值金额
            $list[$key]["ServerName"] =$this->getServerName($value['serverid']);   //游戏房间名称
        }
        $data['code'] = 0;
        $data['message'] = '';
        $data['count'] = $count;
        $data['data'] = $list;
        $this->ajaxReturn($data,'json');
    }

     /*
     * 用户的 全部盈亏记录
     * messagebunkoall
     */
    public function messagebunkoall(){

        $condi=$_GET;
        $condi=array_merge($condi,$_POST);
        $limit = (int)10;
        $pa=$condi['p']?(int)$condi['p']:(int)1;
        $p=$condi['p']?(int)$condi['p']-1:(int)0;
        $skip=$p*$limit;
        
        $where =' 1=1 ';
        if($condi['id']){
            $where .= ' AND gameid_virtual= '.(int)trim($condi['id']);  //gameid_virtual serverid_virtual time_virtual
        }
        if($condi['serverid']){
            $where .= ' AND serverid_virtual= '.(int)trim($condi['serverid']);

        }
        if($condi['start_time']){
              $where .= ' and (time_virtual between "'.$condi['start_time'].' 00:00:00"  and  "'.$condi['start_time'].' 23:59:59") ';
        }else{
              $where .= ' and (time_virtual between "'.date("Y-m-d",time()).' 00:00:00"  and  "'.date("Y-m-d",time()).' 23:59:59") ';

        }   

        $lists =  $this->gamelog("SELECT * FROM game_player where $where order by time_virtual DESC limit $skip,$limit");
        $count= $this->gamelog("SELECT count(*) FROM game_player where $where order by time_virtual DESC");
        $i=0;

       // echo "SELECT * FROM game_player where $where order by time_virtual DESC limit $skip,$limit";
        foreach ($lists as $vo){
            $json=get_object_vars(json_decode($vo['log']));
            $result[$i]['betScoreInfo']=$json['betScoreInfo']; 
            $result[$i]['betScore']=$json['betScore']; 
            $result[$i]['zjScore']=$json['betScore']+$json['caculScore']; 
            $result[$i]['caculScore']=$json['caculScore'];
            $result[$i]['caculScoreInfo']= $json['caculScoreInfo'];
            $result[$i]['detailInfo']=$json['detailInfo'];
            $result[$i]['gameID']=$json['gameID'];
            $result[$i]['nickName']=$json['nickName'];
            $result[$i]['serverID']=$this->GetGameNameByID($json['serverID']);
            $result[$i]['tableID']=$json['tableID'];
            $result[$i]['time']=$json['time'];
            $result[$i]['tax']=$json['tax'];
            $result[$i]['currentScore']=$json['currentScore'];  //身上
            if(array_key_exists('bankGold',$json)){
                $result[$i]['bankGold']=$json['bankGold'];  //银行资产
                $result[$i]['totalGold']=$json['bankGold']+$json['currentScore'];  //总资产
            }else{
                $result[$i]['bankGold']='未统计';  //银行资产
                $result[$i]['totalGold']=$json['currentScore'];  //总资产
            }
            $i++;
        }

        $info= $this->game("select ServerID,ServerName from cfg_GameRoomInfo");
        $str='<option value=\'\'>--全部--</option>';
        foreach ($info as $key => $value) {
            if($condi['serverid']==$value['ServerID']){$xz='selected';}else{$xz='';}
            $str .='<option value='.$value['ServerID'].' '.$xz.'>'.$value['ServerName'].'</option>';
        }
        
        $show = $this->page_show($count[0]['count(*)'],$limit,$p); 
        $shows=$show;
        $pg=array_pop($shows);
        if(!$condi['start_time']){$condi['start_time']=date("Y-m-d",time());}
        if(!$condi['serverid']){$t='全部';}else{$t=$this->GetGameNameByID($condi['serverid']);}
        $logs=$t.'--'.$condi['start_time'];
        $r=$this-> actionLog($condi['id'],'查询了gameid为','用户的游戏详情',$logs);
        $this->assign("totalPages",$pg);
        $this->assign("set",$str);
        $this->assign("p",$pa);
        $this->assign("count",$count[0]['count(*)']);
        $this->assign("condi",$condi);
        $this->assign("lists",$result);
        $this->assign("page_show",$show);
        $this->display('messagebunko_all');
        
        
    }

     /**
      *导出当天用户 个人游戏详情
     **/
    public function  exl_game_group(){
        $where =' 1=1 ';
        $where .= ' AND gameid_virtual= '.(int)trim($_GET['gameid']);  //gameid_virtual serverid_virtual time_virtual
        $where .= ' and (time_virtual between "'.$_GET['time'].' 00:00:00"  and  "'.$_GET['time'].' 23:59:59") ';
        $lists =  $this->gamelog("SELECT * FROM game_player where $where order by time_virtual DESC");
        $i=0;
        foreach ($lists as $vo){
            $json=get_object_vars(json_decode($vo[log]));
            // $result[$i]['time']=$json['time'];
            $result[$i]['gameID']=$json['gameID'];
            $result[$i]['nickName']=$json['nickName'];
            $result[$i]['serverID']=$this->GetGameNameByID($json['serverID']);
            $result[$i]['betScore']=$json['betScore']; 
            $result[$i]['zjScore']=$json['betScore']+$json['caculScore']; 
            $result[$i]['caculScore']=$json['caculScore'];
            $result[$i]['tax']=$json['tax'];
            if(array_key_exists('bankGold',$json)){
                $result[$i]['bankGold']=$json['bankGold'];  //银行资产
                $result[$i]['totalGold']=$json['bankGold']+$json['currentScore'];  //总资产
            }else{
                $result[$i]['bankGold']='未统计';  //银行资产
                $result[$i]['totalGold']=$json['currentScore'];  //总资产
            }
            $result[$i]['currentScore']=$json['currentScore'];  //身上
            $i++;
        }
        if($result){
            $filename = $_GET['time'].'的个人游戏详情'.date('YmdHis');
            $header = array('游戏ID','玩家昵称','游戏项目','下注金额','开奖金额','盈亏','收税','总资产','当前金币','银行金币');
            $index = array('gameID','nickName','serverID','betScore','zjScore','caculScore','tax','totalGold','currentScore','bankGold');
            $this->createtable($result,$filename,$header,$index);
        }
    }


    /******
    用户的游戏信息数据
     *****/
    public function getGameinfo(){
        S(array('type'=>'file','prefix'=>'gameinfo','expire'=>60*60*24));
        $useraccount = M('','','DB_CONFIG2');
        $url = pageurl(__SELF__);
        $pagesize = empty($url['limit'])?10:$url['limit'];
        $page = empty($url['page'])?1:$url['page'];
        $state = ($page-1)*$pagesize;

        if($url['gameid'] > 0 && !empty($url['gameid'])){
            $where['gameid'] = array('eq',$url['gameid']);
        }

        if(!empty($url['time']) && !empty($url['end'])){
            $where['time'] = array('between',array($url['time'],$url['end']));
        }

        if($url['time'] != date('Y-m-d')){
            $list = S('gameinfo_list'.$page.$pagesize);
            $count2 = S('gameinfo_count');
            $count = count($list);
            if($count <= 0 || $count !=$count2 || empty($list) || !empty($url['gameid']) || !empty($url['time'])){
                $list = $useraccount->table('game_player')->field("COUNT(gameid) count,COUNT(serverid) scount ,DATE_FORMAT(time,'%Y-%m-%d') time, SUM(tax) tax,SUM(betscore) betscore,gameid,serverid ,SUM(rewardscore) rewardscore")->where($where)->group("serverid,DATE_FORMAT(time,'%Y-%m-%d')")->limit($state,$pagesize)->order('time desc')->select();
                foreach ($list as $key => $value) {
                    // $list[$key]["goldnum"] =$value["currentscore"] + $value['bankscore'];  //金币总数 = 玩家身上携带分数 + 银行分数
                    $list[$key]["ServerName"] =$this->getServerName($value['serverid']);   //游戏房间名称
                    $list[$key]["betscore"] =round($value['betscore']/1000,2);   //总下注金额
                    $list[$key]["rewardscore"] =round($value['rewardscore']/1000,2); //总开奖金额
                    $list[$key]["caculscore"] =round($value['caculscore']/1000,2);   //总盈亏
                }
                $count = count($list);
                S('gameinfo_list'.$page.$pagesize,$list);
                S('gameinfo_count',$count);
            }
        }else{
            $list = $useraccount->table('game_player')->field("COUNT(gameid) count,COUNT(serverid) scount ,DATE_FORMAT(time,'%Y-%m-%d') time, SUM(tax) tax,SUM(betscore) betscore,SUM(caculscore) caculscore ,gameid,serverid ,SUM(rewardscore) rewardscore")->where($where)->group("serverid,DATE_FORMAT(time,'%Y-%m-%d')")->limit($state,$pagesize)->order('time desc')->select();
            foreach ($list as $key => $value) {
                // $list[$key]["goldnum"] =$value["currentscore"] + $value['bankscore'];  //金币总数 = 玩家身上携带分数 + 银行分数
                $list[$key]["ServerName"] =$this->getServerName($value['serverid']);   //游戏房间名称
                $list[$key]["betscore"] =round($value['betscore']/1000,2);   //总下注金额
                $list[$key]["rewardscore"] =round($value['rewardscore']/1000,2); //总开奖金额
                $list[$key]["caculscore"] =round($value['caculscore']/1000,2);   //总盈亏
            }

            $count = count($list);
        }


        $data['code'] = 0;
        $data['message'] ='';
        $data['count'] = $count;
        $data['data'] = $list;
        $this->ajaxReturn($data,'json');
    }


    /******
        用户的游戏信息
    *****/
     public function gameinfo(){
        $this->CheckPower('3004');
        $url = pageurl(__SELF__);
        $this->assign("gameid",$url['gameid']);
        $this->assign("time",date('Y-m-d'));
        $this->display();

    }
    ///个人的游戏信息
    public function gameinfo_oneuser(){
        $seid= $_GET['severid'];
        $time= $_GET['time'];
        $gameid= $_GET['gameid'];
        $where = '';
        if($time){
              // $t1=$time.' 00:00:00"';
              // $t2=$time.' 23:59:59"';
              // $where .= ' time_virtual>= "'.$t1;
              // $where .= ' and time_virtual<= "'.$t2;
              $where .= '  (time_virtual between "'.$time.' 00:00:00"  and  "'.$time.' 23:59:59") ';
        } 
        $res=$this->gamelog("SELECT SUM(JSON_EXTRACT(log, '$.caculScore')) as amount,
                            SUM(JSON_EXTRACT(log, '$.betScore')) as bet,
                            SUM(JSON_EXTRACT(log, '$.tax')) as tax,count(id) as acj  FROM game_player  
                            where $where AND serverid_virtual=".(int)$seid."
                            AND gameid_virtual=".(int)$gameid."  GROUP BY SUBSTR(time_virtual,1,10)");
        $result['amount']=0;
        $result['tax']=0;
        $result['servid'] = $_GET['severid'];
        $result['kj']=0;
        $result['bet']=0;
         if($res){
            foreach ($res as $key => $value) {
                $result['amount']+=$value['amount'];   ////盈亏
                $result['tax']+=$value['tax'];     //税收
                $result['bet']+=$value['bet'];    //总下注金额
                $result['kj']+=($value['bet']+$value['amount']);  ///开奖
                
            }
            $result['acj']=$res[0][acj];  //下注次数
        }
        $this->ajaxReturn($result); 
    }
    /*
        用户游戏下注金额  开奖金额 税收 盈亏 总记录
    */
    public function GetAllUserMonLog($accountid,$gameID){
    }
    /*
     * 用户的 一个游戏的输赢详情
     * messagebunko_detail
     */
    public function messagebunko_detail(){
        $this->display('messagebunko_details');
    }

    /*
     *
     * 增加代理
     * 修改 sqlsrv data_useraccount 表 usertype
     * 同时插入mysql 操作日志 data_agency表
     */
    public function agent()
    {
        $limit= $this->page_count ;
        $p = $_GET['p'];
        $p = $p ? $p : 1;         //第几页
        $firstRow = ($p - 1) * $limit;
        $where='';
       //判断类型  代理  渠道 送分 推广
        $_GET['tradetype']=$_GET['tradetype']?$_GET['tradetype']:1;
        $s='';
        if($_GET['tradetype']==1){   //代理
            $where .= ' userKind=1 and usertype=6 and disablelogin=0 ';
            $s='代理';
        }else if($_GET['tradetype']==2){  //渠道
            $where .= ' userKind=3 and usertype=6 and disablelogin=0 ';
            $s='渠道';
        }else if($_GET['tradetype']==3){   //推广
            $where .= ' userKind=2 and usertype=7 and disablelogin=0 ';
            $s='推广';
        } 

        if(isset($_GET['gameid']) && is_numeric($_GET['gameid']))
        {
            $where .=" and  gameid={$_GET['gameid']}  ";
            $lists = $this->game("SELECT   accountid,nickname,gameid,regtime,logouttime  FROM data_useraccount   
                             WHERE   $where limit $firstRow,$limit");
            $count=$this->game("SELECT  count(*) as count FROM data_useraccount    WHERE   $where ");
        }else{
              $lists = $this->game("SELECT   accountid,nickname,gameid,regtime,logouttime  FROM data_useraccount   
                             WHERE   $where limit $firstRow,$limit");
              $count=$this->game("SELECT  count(*) as count FROM data_useraccount    WHERE   $where ");
        }
        foreach ($lists as $key => $value) {
             $accountids=$value['accountid'];
              $allmoney = $this->game("
                    SELECT   Score+bankgold as allmoney FROM data_gamescoreinfo   WHERE  AccountID = {$value['accountid']} 
              ");
              $lists[$key]['allmoney'] = reset(reset($allmoney));
             $log_result = $this->weblog("
                  SELECT operator,datetime FROM data_agent WHERE accountid=$accountids ;
                ");
             $lists[$key]['operator']=$log_result[0]['operator'];
             $lists[$key]['datetime']=$log_result[0]['datetime'];
             $lists[$key]['regtime'] =substr($value['regtime'],0,19);
             $lists[$key]['logouttime'] =substr($value['logouttime'],0,19);
        }

        $sorts = array_column($lists, 'datetime');      
        array_multisort($sorts, SORT_DESC, $lists); 
        //操作日志
        if($_GET['gameid']){
            $r=$this-> actionLog($_GET['gameid'],'查询了gameid为',$s);  
        }else{
            $r=$this-> actionLog('全部','查询了',$s);  
        }
        $page_show = $this->page_show($count, $this->page_count,$p);
        $shows=$page_show;
        $pg=array_pop($shows);
        $this->assign('p', $p);
        $this->assign('count', reset(reset($count)));
        $this->assign('totalPages', $pg);
        $this->assign("lists", $lists);
        $this->assign("condi",$_GET);
        $this->display();
    }

    //取消代理
    public function deldl(){
        if($_GET['accountid']){
            $return_accountid = $_GET['accountid'];
            $agentadd = $this->game("
             UPDATE  data_useraccount SET userKind='0',usertype='2' WHERE accountid=$return_accountid
            ");
            $log_result = $this->weblog("DELETE FROM  data_agent  where accountid= $return_accountid");
            if ($agentadd) {
               if($_GET['lx']==1){ $s='代理';}else if($_GET['lx']==2){ $s='渠道';}elseif($_GET['lx']==3){ $s='推广';} 
                $r=$this-> actionLog($return_accountid,'取消了accountid为',$s);
                $result['code']='success';
                $this->ajaxReturn($result); 
            }else{
                $result['code']='fail';
                $this->ajaxReturn($result); 
            }     
        } 
    }    /*
     * 添加代理人
     *
     */
    public function agentadd()
    {
        $this->CheckPower('4001'); 
        if(!isset($_GET['gameid']) && !is_numeric($_GET['gameid'])){
            // $this->err404("会员id不能为空", "!");
            $result['code']='会员id不能为空';
            $this->ajaxReturn($result); 
        }
        $accountid =$_GET['gameid'];   //游戏ID  gameid
        if(!$accountid){
            // $this->err404("会员id不能为空", "!");
            $result['code']='会员id不能为空';
            $this->ajaxReturn($result); 
        }
        if ($accountid) {
            $accountid = "'" . $accountid . "'";
            $lists = $this->game("
            SELECT accountid,account,gameid,nickname,userKind,usertype  FROM data_useraccount  WHERE gameid=$accountid
            ");
            $return_accountid = $lists[0]['accountid'];
            $return_usertype = $lists[0]['usertype'];  ///6代理   2普通
            $return_userKind = $lists[0]['userKind'];  //代理
            if (!$return_accountid) {
                // $this->err404("id无效，查无此人", "！");
                $result['code']='id无效,查无此人';
                $this->ajaxReturn($result); 
            }
            if ($return_userKind == '1' &&  $return_usertype=='6') {
                // $this->err404("此会员 已是代理人", "！");
                $result['code']='此会员已是代理人';
                $this->ajaxReturn($result); 
            }
            if ($return_usertype != '2') {
                // $this->err404("此会员<br>不是【正式且绑定手机号的会员】<br>不能成为代理人", "！");
                $result['code']='此会员<br>不是【正式且绑定手机号的会员】<br>不能成为代理人';
                $this->ajaxReturn($result); 
            }

            if ($return_accountid) {
                $return_accountid = "'" . $return_accountid . "'";
                $agentadd = $this->game("
                UPDATE  data_useraccount SET userKind='1',usertype='6' WHERE gameid=$accountid;
                ");
            }
            if (!$agentadd) {
                // $this->err404("此会员， 设置代理人失败", "err");
                $result['code']='此会员， 设置代理人失败';
                $this->ajaxReturn($result); 
            }
            if ($agentadd) {  // 写入操作记录
                $r=$this-> actionLog($_GET['gameid'],'添加了gameid为','代理用户');  
                $accountid = $lists[0]['accountid'];
                $account = $lists[0]['account'];
                $gameid = $lists[0]['gameid'];
                $nikename = "'" . $lists[0]['nickname'] . "'";
                $rank = 1; //代理人级别
                $operator = "'" . $_SESSION['ltq_game_admin_user']['name'] . "'";
                $operatorid = $_SESSION['ltq_game_admin_user']['id'];
                $datetime = "'" . date('Y-m-d H:i:s', time()) . "'";
                $log_result = $this->weblog("INSERT INTO data_agent (accountid,nikename,gameid,ranks,operator,operatorid,datetime) 
                                              VALUES ($accountid,$nikename,$gameid,$rank,$operator,$operatorid,$datetime)");
                
            }
            if (!$log_result) {
                // $this->err404("添加代理人成功<br>写入操作记录失败", "err");
                $result['code']='添加代理人成功<br>写入操作记录失败';
                $this->ajaxReturn($result); 
            }
            if ($log_result) {
                $lists = $this->weblog("
                SELECT * FROM data_agent WHERE operator=$operator AND datetime=$datetime
                ");
            }
            if (!$lists) {
                // $this->err404("查询操作日志失败", "!");
                $result['code']='查询操作日志失败';
                $this->ajaxReturn($result); 
            }
        }
          if ($agentadd) {
                // $this->err404("代理设置成功", "success");
                $result['code']='success';
                $this->ajaxReturn($result); 
          }
    }


    //设置代理  普通玩家   渠道
    public  function design(){
        $this->CheckPower('3011');
        $useraccount = M('','','DB_CONFIG1');
        $url = pageurl(__SELF__);
        $gameid =trim($url['gameid']);
        $lists = $useraccount->table('data_useraccount')->field("accountid,account,gameid,nickname,usertype ")->where("gameid=$gameid")->select();
        $this->assign('lists',$lists);
        $this->assign('gameid',$gameid);
        $this->display();

    }

    // 渠道  推广
    public function design_dali(){
         $gameid=$_GET['gameid']; 
         $level=$_GET['level'];
         $lists = $this->game("SELECT accountid,account,gameid,nickname,userKind,usertype  FROM data_useraccount  WHERE gameid=$gameid ");
         $return_usertype = $lists[0]['usertype'];  ///6代理   2普通
         if($return_usertype !=2  && $return_usertype !=6 && $return_usertype !=7){
              $result['code']='此会员<br>不是【正式且绑定手机号的会员】<br>不能成为代理人';
              $this->ajaxReturn($result); 
         }else{
              if($level == 1){ //普通玩家
                  $agentadd = $this->game(" UPDATE  data_useraccount SET userKind='0',usertype='2' WHERE gameid=$gameid ");
                  $s='普通玩家';
                  $log_result = $this->weblog("DELETE FROM  data_agent  where gameid= $gameid");
              }else{
                      if($level == 2){  //推广  userKind=2
                          $agentadd = $this->game(" UPDATE  data_useraccount SET userKind='2',usertype='7' WHERE gameid=$gameid ");
                          $s='推广';
                      }else if($level == 3){  //渠道
                          $agentadd = $this->game(" UPDATE  data_useraccount SET userKind='3',usertype='6' WHERE gameid=$gameid ");
                          $s='渠道';
                      }else if($level == 4){ //代理
                              $agentadd = $this->game(" UPDATE  data_useraccount SET userKind='1',usertype='6' WHERE gameid=$gameid ");
                              $s='代理';
                      } 
                      $log_result = $this->weblog("DELETE FROM  data_agent  where gameid= $gameid");
                      if ($agentadd) {  // 写入操作记录
                              $r=$this-> actionLog($gameid,'添加了gameid为',$s);  
                              $accountid = $lists[0]['accountid'];
                              $account = $lists[0]['account'];
                              $gameid = $lists[0]['gameid'];
                              $nikename = "'" . $lists[0]['nickname'] . "'";
                              $rank = 1; //代理人级别
                              $operator = "'" . $_SESSION['ltq_game_admin_user']['name'] . "'";
                              $operatorid = $_SESSION['ltq_game_admin_user']['id'];
                              $datetime = "'" . date('Y-m-d H:i:s', time()) . "'";
                              $log_result = $this->weblog("INSERT INTO data_agent (accountid,nikename,gameid,ranks,operator,operatorid,datetime) 
                                                  VALUES ($accountid,$nikename,$gameid,$rank,$operator,$operatorid,$datetime)");
                      }  
              } 
             if($level==1){ $s='普通玩家';}else if($level==2){ $s='推广';}elseif($level==3){ $s='渠道';}elseif($level==4){ $s='代理';}
             $r=$this-> actionLog($gameid,'添加了accountid为',$s); 
             $result['code']='success';
             $this->ajaxReturn($result);  
         }
    }


  
    /*
     *  单个会员个人中心
     *  查询单个用户信息
     *  被调用的弹框操作
     *
     */
    public function mycenter()
    {
        $this->CheckPower('3001');
        $useraccount = M('','','DB_CONFIG1');
        $url = pageurl(__SELF__);
        $gameid = $url['gameid'];
        if ($url['gameid']) {
            $gameid = $url['gameid'];
        }
        $where['gameid'] = array('eq',$gameid);
        if (!empty($gameid)) {
            $lists = $useraccount->table('data_useraccount')->field('accountid,gameid,nickname,registeraddr,registertime,lastloginaddr,logintime,viplevel,disablelogin,vipexperience')->where($where)->find();
        }
        $lists['viplevel']=viplevel($lists['vipexperience']);
        $lists['experience'] =floor($lists['vipexperience']/1000);
        $this->actionLog($gameid,'查询了gameid为','用户的个人信息');
        $this->assign("lists", $lists);
        $this->display();
    }



    //扣除金币
    public function kcmoney(){
        $this->CheckPower('3010');
        $accountid=$_GET['accountid'];
        $lists = $this->game("
            SELECT  a.nickname,b.Score,b.bankgold,b.AccountID 
            FROM data_useraccount AS a , data_gamescoreinfo AS b  
            WHERE  a.accountid = b.AccountID    AND b.AccountID=$accountid;
        ");
        $this->assign('result',$lists);
        $this->display();
    }
    //扣除金额
    public function kcmoneys(){
          $accountid=$_GET['accountid'];
          $kcjb=$_GET['kcjb'];
          $kcjbs=$_GET['kcjbs'];
          $lists = $this->game("
            UPDATE data_gamescoreinfo  SET bankgold=$kcjb WHERE  AccountID=$accountid
            ");
          $datetime = "'" . date('Y-m-d H:i:s', time()) . "'";
          $operator = "'" . $_SESSION['ltq_game_admin_user']['name'] . "'";
          $operatorid = $_SESSION['ltq_game_admin_user']['id'];
          $list=$this->weblog("INSERT INTO data_kcmoney VALUES ('',$accountid,$kcjbs,$operator,$operatorid,$datetime)");
          $r=$this->actionLog((int)$accountid,'扣除了accountid为','用户的银行金额');
          if($lists){
            $this->ajaxReturn('扣除成功'); 
          }else{
            $this->ajaxReturn('扣除失败'); 
          }
    } 


    /*
     * 字段名称 变成中文
     * data_useraccount 注册会员表
     * return array
     */
    protected function fieldZH($arr)
    {
        $arrOne = reset($arr);

        if (!is_array($arrOne)) { //$data 1维数组
            $reset = $this->fieldNeedZH($arr);
            return $reset;
        }
        if (is_array($arrOne)) { //$lists 2维数组
            foreach ($arr as $v) {
                $reset[] = $this->fieldNeedZH($v);
            }
            return $reset;
        }

    }


    /*
     * 汉化 所有字段
     *  data_useraccount 注册会员表
     *  $arr 一维数组
     *  return array
     */
    protected function fieldAllZH($arr)
    {
        $reset['accountid']['value'] = $arr['accountid'];
        $reset['accountid']['ZH'] = "会员ID";

        $reset['account']['value'] = $arr['account'];
        $reset['account']['ZH'] = "注册名称";

        $reset['gameid']['value'] = $arr['gameid'];
        $reset['gameid']['ZH'] = "游戏ID";

        $reset['nikename']['value'] = $arr['nikename'];
        $reset['nikename']['ZH'] = "用户名";

        $reset['faceid']['value'] = $arr['faceid'];
        $reset['faceid']['ZH'] = "头像ID";

        $reset['experience']['value'] = $arr['experience'];
        $reset['experience']['ZH'] = "经验值";

        $reset['sex']['value'] = $arr['sex'];
        $reset['sex']['ZH'] = "性别";

        $reset['moormachine']['value'] = $arr['moormachine'];
        $reset['moormachine']['ZH'] = "绑定机器";

        $reset['usertype']['value'] = $arr['usertype'];
        $reset['usertype']['ZH'] = "用户类型";

        $reset['devicetype']['value'] = $arr['devicetype'];
        $reset['devicetype']['ZH'] = "设备类型";

        $reset['spreaderaccount']['value'] = $arr['spreaderaccount'];
        $reset['spreaderaccount']['ZH'] = "推荐人账号";

        $reset['phonenum']['value'] = $arr['phonenum'];
        $reset['phonenum']['ZH'] = "绑定手机";

        $reset['disablelogin']['value'] = $arr['disablelogin'];
        $reset['disablelogin']['ZH'] = "禁止登陆";

        $reset['crontolstatus']['value'] = $arr['crontolstatus'];
        $reset['crontolstatus']['ZH'] = "操作状态";

        $reset['use_novice_card']['value'] = $arr['use_novice_card'];
        $reset['use_novice_card']['ZH'] = "新手卡";

        $reset['winwealth']['value'] = $arr['winwealth'];
        $reset['winwealth']['ZH'] = "取胜";

        $reset['bankgold']['value'] = $arr['bankgold'];
        $reset['bankgold']['ZH'] = "库金";

        $reset['row_number']['value'] = $arr['row_number'];
        $reset['row_number']['ZH'] = "行号";

        $reset['country']['value'] = $arr['country'];
        $reset['country']['ZH'] = "国家";

        $reset['province']['value'] = $arr['province'];
        $reset['province']['ZH'] = "省份";

        $reset['city']['value'] = $arr['city'];
        $reset['city']['ZH'] = "城市";

        $reset['openid']['value'] = $arr['openid'];
        $reset['openid']['ZH'] = "微信openid";

        $reset['unionid']['value'] = $arr['unionid'];
        $reset['unionid']['ZH'] = "微信unionid";

        $reset['refresh_token']['value'] = $arr['refresh_token'];
        $reset['refresh_token']['ZH'] = "微信refresh_token";

        $reset['headimgurl']['value'] = $arr['headimgurl'];
        $reset['headimgurl']['ZH'] = "头像地址";

        $reset['pwd']['value'] = $arr['pwd'];
        $reset['pwd']['ZH'] = "登录密码";

        $reset['bankpwd']['value'] = $arr['bankpwd'];
        $reset['bankpwd']['ZH'] = "库金密码";

        return $reset;
    }

    /*
    * 汉化 需要的 字段
    *  data_useraccount 注册会员表
    *  $arr 一维数组
    *  return array
    */
    protected function fieldNeedZH($arr)
    {
        if (array_key_exists("accountid", $arr)) {
            $reset['accountid']['value'] = $arr['accountid'];
            $reset['accountid']['ZH'] = "会员ID";
        }
        if (array_key_exists("account", $arr)) {
            $reset['account']['value'] = $arr['account'];
            $reset['account']['ZH'] = "注册名称";
        }
        if (array_key_exists("gameid", $arr)) {
            $reset['gameid']['value'] = $arr['gameid'];
            $reset['gameid']['ZH'] = "游戏ID";
        }
        if (array_key_exists("nikename", $arr)) {
            $reset['nikename']['value'] = $arr['nikename'];
            $reset['nikename']['ZH'] = "用户名";
        }
        if (array_key_exists("faceid", $arr)) {
            $reset['faceid']['value'] = $arr['faceid'];
            $reset['faceid']['ZH'] = "头像ID";
        }
        if (array_key_exists("experience", $arr)) {
            $reset['experience']['value'] = $arr['experience'];
            $reset['experience']['ZH'] = "经验值";
        }
        if (array_key_exists("sex", $arr)) {
            $reset['sex']['value'] = $arr['sex'];
            $reset['sex']['ZH'] = "性别";
        }
        if (array_key_exists("moormachine", $arr)) {
            $reset['moormachine']['value'] = $arr['moormachine'];
            $reset['moormachine']['ZH'] = "绑定机器";
        }
        if (array_key_exists("usertype", $arr)) {
            $reset['usertype']['value'] = $arr['usertype'];
            $reset['usertype']['ZH'] = "用户类型";
        }
        if (array_key_exists("devicetype", $arr)) {
            $reset['devicetype']['value'] = $arr['devicetype'];
            $reset['devicetype']['ZH'] = "设备类型";
        }
        if (array_key_exists("spreaderaccount", $arr)) {
            $reset['spreaderaccount']['value'] = $arr['spreaderaccount'];
            $reset['spreaderaccount']['ZH'] = "推荐人账号";
        }
        if (array_key_exists("phonenum", $arr)) {
            $reset['phonenum']['value'] = $arr['phonenum'];
            $reset['phonenum']['ZH'] = "绑定手机";
        }
        if (array_key_exists("disablelogin", $arr)) {
            $reset['disablelogin']['value'] = $arr['disablelogin'];
            $reset['disablelogin']['ZH'] = "禁止登陆";
        }
        if (array_key_exists("crontolstatus", $arr)) {
            $reset['crontolstatus']['value'] = $arr['crontolstatus'];
            $reset['crontolstatus']['ZH'] = "操作状态";
        }

        if (array_key_exists("use_novice_card", $arr)) {
            $reset['use_novice_card']['value'] = $arr['use_novice_card'];
            $reset['use_novice_card']['ZH'] = "新手卡";
        }

        if (array_key_exists("winwealth", $arr)) {
            $reset['winwealth']['value'] = $arr['winwealth'];
            $reset['winwealth']['ZH'] = "取胜";
        }

        if (array_key_exists("bankgold", $arr)) {
            $reset['bankgold']['value'] = $arr['bankgold'];
            $reset['bankgold']['ZH'] = "库金";
        }
        if (array_key_exists("row_number", $arr)) {
            $reset['row_number']['value'] = $arr['row_number'];
            $reset['row_number']['ZH'] = "行号";
        }

        if (array_key_exists("country", $arr)) {
            $reset['country']['value'] = $arr['country'];
            $reset['country']['ZH'] = "国家";
        }
        if (array_key_exists("province", $arr)) {
            $reset['province']['value'] = $arr['province'];
            $reset['province']['ZH'] = "省份";
        }
        if (array_key_exists("city", $arr)) {
            $reset['city']['value'] = $arr['city'];
            $reset['city']['ZH'] = "城市";
        }
        if (array_key_exists("openid", $arr)) {
            $reset['openid']['value'] = $arr['openid'];
            $reset['openid']['ZH'] = "微信openid";
        }
        if (array_key_exists("unionid", $arr)) {
            $reset['unionid']['value'] = $arr['unionid'];
            $reset['unionid']['ZH'] = "微信unionid";
        }
        if (array_key_exists("refresh_token", $arr)) {
            $reset['refresh_token']['value'] = $arr['refresh_token'];
            $reset['refresh_token']['ZH'] = "微信refresh_token";
        }
        if (array_key_exists("headimgurl", $arr)) {
            $reset['headimgurl']['value'] = $arr['headimgurl'];
            $reset['headimgurl']['ZH'] = "头像地址";
        }
        if (array_key_exists("pwd", $arr)) {
            $reset['pwd']['value'] = $arr['pwd'];
            $reset['pwd']['ZH'] = "登录密码";
        }
        if (array_key_exists("bankpwd", $arr)) {
            $reset['bankpwd']['value'] = $arr['bankpwd'];
            $reset['bankpwd']['ZH'] = "库金密码";
        }

        return $reset;
    }


    /*
     * 测试类
     */
    public function mytry()
    {
        //socket 客户端测试  //192.168.1.88,9300
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("创建socket失败：" . socket_strerror(socket_last_error()));// 创建 tcp 连接
        $con = socket_connect($socket, '192.168.1.76', 9300) or die("连接失败：" . socket_strerror(socket_last_error($socket)));// 连接到远程
        if ($con) {
            echo "连接成功66\n";
        } else {
            echo "连接失败55\n";
        }
        while ($con) {
            $words = "";

            $size = 123;
            $msg_type = 123;
            $msg_id = 123;
            $head = pack("c",0x66).pack("c",0).pack("s",$size).pack("s",$msg_type).pack("s",$msg_id);
            if(!@socket_write($socket, $head, 8))
            {
                socket_close($socket);
                return false;
            }
            die;
            //$http = ;
            socket_write($socket, $http, strlen($http));
            //socket_write($socket,$words);
            echo "等待远程返回数据";
            echo "\n";
            die;
            $hear = socket_read($socket, 1024);
            echo '远程返回数据：' . $hear;
            echo "\n";
            if ($words == "bye\r\n") {
                break;
            }
        }
        socket_shutdown($socket);//关闭连接
        socket_close($socket);//关闭数据

        //socket 服务器端测试
        set_time_limit(0);// 清除时间限制
        ob_implicit_flush();// 直接输出到浏览器
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);//创建socket
        socket_bind($socket, '192.168.50.141', 9300);//绑定监听端口
        socket_listen($socket);// 端口监听
        $acpt = socket_accept($socket);// 接收消息
        echo "远程连接成功!\n";
        while ($acpt) {
            echo "请输入远程发送命令!\n";
            $words = fgets(STDIN);// 获取命令行输入信息
            socket_write($acpt, $words);// 发送命令行获取的信息 到客户端
            $hear = socket_read($acpt, 1024);// 读取客户端 输入信息
            echo '客户端返回信息:' . $hear . "\r\n";// 打印头
            if ("bye\r\n" == $hear) {// 如果等于 结束
                socket_shutdown($acpt);// 关闭 连接
                break;// 跳出循环
            }
            usleep(1000);// 休息 1秒钟
        }
        socket_close($socket);

    }

    /*
     * socket 测试类
     */
    public function mysocket($url='www.58hao.com', $type = "GET", $post_data = NULL)
    {
        $type = strtoupper($type);

        $http_info = array();
        $url2 = parse_url($url);
        $url2['host']='';
        if(($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0)
        {
            return false;
        }
        
        socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO,
            array("sec"=>1, "usec"=>0));
        $url2["path"] = ($url2["path"] == "" ? "/" : $url2["path"]);
        $url2["port"] = ($url2["port"] == "" ? 80 : $url2["port"]);
        //$host_ip = http_get_host_ip($url2["host"]);
        $host_ip = $url2["host"];
        if(($result = socket_connect($socket, $host_ip, $url2["port"])) < 0)
        {
            socket_close($socket);
            return false;
        }

        $size = 123;
        $msg_type = 123;
        $msg_id = 123;
        $head = pack("c",0x66).pack("c",0).pack("s",$size).pack("s",$msg_type).pack("s",$msg_id);
        if(!@socket_write($socket, $head, 8))
        {
            socket_close($socket);
            return false;
        }
        $request =  $url2["path"] . ($url2["query"] != "" ? "?" . $url2["query"] : "") . ($url2["fragment"] != "" ? "#" . $url2["fragment"] : "");
        dump($request);
        dump($url2);
        if($type == "GET")
        {//GET method
            $in = "GET " . $request . " HTTP/1.1\r\n";
            $in .= "Accept: */*\r\n";
            $in .= "User-Agent: Lowell-Agent\r\n";
            $in .= "Host: " . $url2["host"] . "\r\n";
            $in .= "Connection: Close\r\n\r\n";
            dump($in);
            die;
            if(!socket_write($socket, $in, strlen($in)))
            {
                socket_close($socket);
                return false;
            }
            unset($in);
        }
        else if($type == "POST")
        {
            $needChar = false;
            foreach($post_data as $key => $val)
            {
                $post_data2 .= ($needChar ? "&" : "") . urlencode($key) . "=" . urlencode($val);
                $needChar = true;
            }
            $in = "POST " . $request . " HTTP/1.1\r\n";
            $in .= "Accept: */*\r\n";
            $in .= "Host: " . $url2["host"] . "\r\n";
            $in .= "User-Agent: Lowell-Agent\r\n";
            $in .= "Content-type: application/x-www-form-urlencoded\r\n";
            $in .= "Content-Length: " . strlen($post_data2) . "\r\n";
            $in .= "Connection: Close\r\n\r\n";
            $in .= $post_data2 . "\r\n\r\n";
            unset($post_data2);
            if(!@socket_write($socket, $in, strlen($in)))
            {
                socket_close($socket);
                return false;
            }
            unset($in);
        }
        else
        {
            exit;
        }
        $out = "";
        while($buff = @socket_read($socket, 2048))
        {
            $out .= $buff;
        }
        socket_close($socket);
        $pos = strpos($out, "\r\n\r\n");
        $head = substr($out, 0, $pos);
        $status = substr($head, 0, strpos($head, "\r\n"));
        $body = substr($out, $pos + 4, strlen($out) - ($pos + 4));
        if(preg_match("/^HTTP\/\d\.\d\s([\d]+)\s.*$/", $status, $matches))
        {
            if(intval($matches[1]) / 100 == 2)
            {
                return $body;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }

    function sock_post($url, $data = '')
    {
        //$url = parse_url($url);
        $url = 'www.baidu.com';
        $data= '8081';
        $url['scheme'] || $url['scheme'] = 'http';
        $url['host'] || $url['host'] = $_SERVER['HTTP_HOST'];
        $url['path'][0] != '/' && $url['path'] = '/' . $url['path'];
        $query = $data;
        if (is_array($data)) $query = http_build_query($data);

        $fp = @fsockopen($url['host'], $url['port'] ? $url['port'] : 80);
        if (!$fp) return "Failed to open socket to $url[host]";

        fputs($fp, sprintf("POST %s%s%s HTTP/1.0/n", $url['path'], $url['query'] ? "?" : "", $url['query']));
        fputs($fp, "Host: $url[host]/n");
        fputs($fp, "Content-type: application/x-www-form-urlencoded/n");
        fputs($fp, "Content-length: " . strlen($query) . "/n");
        fputs($fp, "Connection: close/n/n");
        dump($fp);
        die;

        fputs($fp, "$query/n");

        $line = fgets($fp, 1024);

        if (@!eregi("^HTTP/1/.. 200", $line)) return;

        $results = "";
        $inheader = 1;
        while (!feof($fp)) {
            $line = fgets($fp, 1024);
            if ($inheader && ($line == "/n" || $line == "/r/n")) {
                $inheader = 0;
            } elseif (!$inheader) {
                $results .= $line;
            }
        }
        fclose($fp);

        return $results;
    }



    //下来框
    public function selects(){

        $str[] = ['id'=>0,'name'=>'离线'];
        $str[] = ['id'=>1,'name'=>'在线代理/渠道/推广'];
        $str[] = ['id'=>2,'name'=>'在线玩家'];
        $str[] = ['id'=>3,'name'=>'全部'];
        $str[] = ['id'=>4,'name'=>'冻结玩家'];
        $str[] = ['id'=>5,'name'=>'测试账号'];
        return $str;
    }

}